package com.itzjc.service.impl;

import com.itzjc.dao.UploadMapper;
import com.itzjc.domain.pojo.*;
import com.itzjc.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * TODO
 *
 * @className: UploadServiceImpl
 * @date: 2021-06-16 10:43
 **/
@Service
public class UploadServiceImpl implements UploadService {
    @Autowired(required = false)
    private UploadMapper uploadMapper;


    @Override
    public void updateImgUrl(String filename) {
//暂时用不到，直接就在project中完成了
    }

    @Override
    @Transactional(transactionManager = "test1TransactionManager")
    public void addDeflectionData(List<DeflectionValue01> deflectionValue01s) {
        //遍历
        for (DeflectionValue01 dfv1 : deflectionValue01s) {
            //通过日期查询相关的数据信息
            int number = uploadMapper.findDeflectionDataByCreateTime(dfv1.getCreateTime());
            //如果没有就调用插入的命令
            if (0 != number) {
                uploadMapper.updateDeflectionData(dfv1);
            } else {
                //如果不存在就调用添加的命令
                uploadMapper.addDeflectionData(dfv1);
            }

        }
    }

    @Override
    @Transactional(transactionManager = "test1TransactionManager")
    public void addDisplacementData(List<DispalcementValue01> dispalcementValue01s) {
        //遍历
        for (DispalcementValue01 dpv1 : dispalcementValue01s) {
            //通过日期查询相关的数据信息
            int number = uploadMapper.findDisplacementDataByCreateTime(dpv1.getCreateTime());
            //如果没有就调用插入的命令
            if (0 != number) {
                uploadMapper.updateDisplacementData(dpv1);
            } else {
                //如果不存在就调用添加的命令
                uploadMapper.addDisplacementData(dpv1);
            }

        }

    }

    @Override
    @Transactional(transactionManager = "test1TransactionManager")
    public void addTemperatureData(List<TemperatureValue01> temperatureValue01s) {
        //遍历
        for (TemperatureValue01 tv1 : temperatureValue01s) {
            //通过日期查询相关的数据信息
            int number = uploadMapper.findTemperatureDataByCreateTime(tv1.getCreateTime());
            //如果没有就调用插入的命令
            if (0 != number) {
                uploadMapper.updateTemperatureData(tv1);
            } else {
                //如果不存在就调用添加的命令
                uploadMapper.addTemperatureData(tv1);
            }
        }
    }

    @Override
    @Transactional(transactionManager = "test1TransactionManager")
    public void addStressData(List<StressValue01> stressValue01s) {
        //遍历
        for (StressValue01 stressValue01 : stressValue01s) {
            //通过日期查询相关的数据信息
            int number = uploadMapper.findStressDataByCreateTime(stressValue01.getCreateTime());
            //如果没有就调用插入的命令
            if (0 != number) {
                uploadMapper.updateStressData(stressValue01);
            } else {
                //如果不存在就调用添加的命令
                uploadMapper.addStressData(stressValue01);
            }
        }

    }

    @Override
    @Transactional(transactionManager = "test1TransactionManager")
    public void addWindData(List<WindValue01> windValue01s) {
        //遍历
        for (WindValue01 windValue01 : windValue01s) {
            //通过日期查询相关的数据信息
            int number = uploadMapper.findWindDataByCreateTime(windValue01.getCreateTime());
            //如果没有就调用插入的命令
            if (0 != number) {
                uploadMapper.updateWindData(windValue01);
            } else {
                //如果不存在就调用添加的命令
                uploadMapper.addWindData(windValue01);
            }
        }
    }
}
